<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="反馈状态" prop="status">
        <el-select v-model="queryParams.status"
                   clearable placeholder="请选择反馈状态"
                   size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_FEEDBACK_STATUS)"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="是否已读" prop="isRead">
        <el-select v-model="queryParams.isRead"
                   clearable placeholder="请输入是否已读"
                   size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_FEEDBACK_READ)"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
        <el-button icon="el-icon-search" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button icon="el-icon-plus" plain size="mini" type="primary"
                   @click="openForm(undefined)">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button :loading="exportLoading" icon="el-icon-download" plain
                   size="mini"
                   type="warning"
                   @click="handleExport">导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
      <el-table-column align="center" label="ID" prop="id"/>
      <el-table-column align="center" label="标题" prop="title"/>
      <el-table-column label="反馈状态" align="center" prop="status">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_FEEDBACK_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="是否已读" align="center" prop="isRead">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_FEEDBACK_READ" :value="scope.row.isRead" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建时间" prop="createTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template v-slot="scope">
          <el-button icon="el-icon-edit" size="mini" type="text"
                     @click="openForm(scope.row.id)">修改
          </el-button>
          <el-button icon="el-icon-delete" size="mini" type="text"
                     @click="handleDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNo" :total="total"
                @pagination="getList"/>
    <!-- 对话框(添加 / 修改) -->
    <FeedbackForm ref="formRef" @success="getList"/>
  </div>
</template>

<script>
import * as FeedbackApi from '@/api/system/feedback';
import FeedbackForm from './FeedbackForm.vue';

export default {
  name: "Feedback",
  components: {
    FeedbackForm,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 问题反馈列表
      list: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        title: null,
        status: null,
        isRead: null,
        createTime: [],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true;
        const res = await FeedbackApi.getFeedbackPage(this.queryParams);
        this.list = res.data.list;
        this.total = res.data.total;
      } finally {
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      await this.$modal.confirm('是否确认删除问题反馈编号为"' + id + '"的数据项?')
      try {
        await FeedbackApi.deleteFeedback(id);
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } catch {
      }
    },
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm('是否确认导出所有问题反馈数据项?');
      try {
        this.exportLoading = true;
        const res = await FeedbackApi.exportFeedbackExcel(this.queryParams);
        this.$download.excel(res, '问题反馈.xls');
      } catch {
      } finally {
        this.exportLoading = false;
      }
    },
  }
};
</script>
